﻿Public Partial Class FrmPortScheduler_Popup
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'Dim lb As Label = CType(Master.FindControl("lbMenu"), Label)
            'lb.Text = "Port Scheduler"
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " var theform = document.forms['aspnetForm'];theform.__EVENTARGUMENT.value = parent.document.getElementById('ctl00_contentplaceholder1_hdfid').value;", True)
        End If
    End Sub

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim Booking_and_Wharf As String = Request.Form("__EVENTARGUMENT").ToString().Replace(",", "")
        If ((txtDate.Text.Trim() <> "") And (txtDateTo.Text.Trim() <> "")) Then
            Dim conn As New System.Data.SqlClient.SqlConnection(connString)
            Dim clsDB As New ClassDatabase
            Dim clsFc As New ClassFunction
            Dim condition As Boolean = True
            Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
            Dim User_Create As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name") & " " & DateTime.Now.ToString("yyyyMMdd:HHmmss")
            Application.Lock()
            conn.Open()
            tran = clsDB.BeginTran(conn)
            If (clsFc.InsertBooking_Wharf(Booking_and_Wharf.Split("$")(0), Booking_and_Wharf.Split("$")(1), txtDate.Text, txtDateTo.Text, "", "", txtRemark.Text, User_Create, CDate(ClassFunctionGetData.CDateT(txtDate.Text)).ToString("dd/MM/yyyy"), CDate(ClassFunctionGetData.CDateT(txtDateTo.Text)).ToString("dd/MM/yyyy"), "N", "", "", conn, tran) < 1) Then
                condition = False
            End If
            If (condition) Then
                clsDB.CommitTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalOK();", True)
            Else
                clsDB.RollBackTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('เกิดความผิดพลาดในการบันทึก');", True)
            End If
            Application.UnLock()
            conn.Dispose()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModal();", True)
    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub
End Class